package com.hxl.demo.service.Impl;

import com.hxl.demo.entity.LaborContract;
import com.hxl.demo.mapper.LaborContractMapper;
import com.hxl.demo.service.LaborContractService;
import com.hxl.demo.tools.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class LaborContractServiceImpl implements LaborContractService {
    @Resource
    private LaborContractMapper laborContractMapper;
    @Override
    public PageInfo<LaborContract> selectLaborContract(int begin, int length, String username) {
        int count = laborContractMapper.getCount(username);
        Map<String, Object> map = new HashMap<>();
        if(username != null) {
            map.put("username", username);
        }
        map.put("begin", begin);
        map.put("length", length);
        PageInfo<LaborContract> pageInfo = new PageInfo<>();
        pageInfo.setTotal(count);
        List<LaborContract> allLaborContract = laborContractMapper.getAllLaborContract(map);
        pageInfo.setData(allLaborContract);
        return pageInfo;
    }

    @Override
    public int updateLabor(LaborContract laborContract) {
        return laborContractMapper.updateLabor(laborContract);
    }
}
